package com.example.demo.service;

import com.example.demo.model.SysRole;
import com.example.demo.repo.SysRoleRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SysRoleService {
    @Autowired
    private SysRoleRepository sysRoleRepository;
    public SysRole findSysRoleByName(String name)
    {
        return sysRoleRepository.findSysRoleByName(name);
    }
    public SysRole getAdminSysRole()
    {
        return sysRoleRepository.findSysRoleByName("ROLE_ADMIN");
    }
    public SysRole getUltimateSysRole()
    {
        return sysRoleRepository.findSysRoleByName("ROLE_ULTIMATE");
    }
    public SysRole getUserSysRole()
    {
        return sysRoleRepository.findSysRoleByName("ROLE_USER");
    }

    public boolean save(SysRole sysRole)
    {
        try {
            if(sysRoleRepository.save(sysRole)!=null) {

                return true;
            }
            else {
                return false;
            }
        }
        catch (Exception e)
        {
            e.printStackTrace();
            return false;
        }
    }
}
